๐Ÿงฎ Sorting Algorithms Visualized!

Watch Teju sort arrays using Bubble, Selection, and Insertion Sort

๐ŸŽฏ Let's Sort This Out!

Hi again! ๐Ÿ‘‹ Today weโ€™re learning three classic sorting algorithms:

Bubble Sort โ†’ Repeatedly swap adjacent elements
Selection Sort โ†’ Find minimum and place it in position
Insertion Sort โ†’ Build sorted portion one by one

๐Ÿซง Bubble Sort

Largest elements "bubble up" to the end in each pass!

64
34
25
12
22
90

64 > 34 โ†’ Swap! Largest numbers rise to the top

Time: O(nยฒ) | Best: O(n) when already sorted | Space: O(1)

๐ŸŽฏ Selection Sort

In each pass, find the smallest element and swap it into place!

12
22
25
34
64
90

Scanning for minimum โ†’ 25 is smallest โ†’ swap with first unsorted

Time: Always O(nยฒ) | Space: O(1) | Fewer swaps than Bubble!

๐Ÿƒ Insertion Sort

Build a sorted portion on the left โ€” insert new card in correct position!

12
22
25
34
64
90

Take 34 โ†’ shift larger elements โ†’ insert in correct spot

Best Case: O(n) nearly sorted | Worst: O(nยฒ) | Great for small or nearly sorted data!

๐ŸŽฎ Live Sorting Demo

โš”๏ธ Which Sort Wins?

Algorithm Time (Worst) Time (Best) Space Stable? Best For
Bubble Sort O(nยฒ) O(n) O(1) Yes Educational
Selection Sort O(nยฒ) O(nยฒ) O(1) No Fewer swaps needed
Insertion Sort O(nยฒ) O(n) O(1) Yes Small or nearly sorted arrays

๐Ÿ† Winner?

Insertion Sort is usually the best among these three for real-world small/nearly-sorted data!